//
//  ChanelDeTailToolBar.m
//  TestApplication
//
//  Created by Hanlingyu on 16/9/12.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "ChanelDeTailToolBar.h"
#import "TAMacro.h"
#import "ChannelToolBarCell.h"
#import "ChannelPostToolbar.h"
#import "UIImageView+WebCache.h"
#import "ChannelPostStar.h"
#import "ChannelPostJoin.h"
#import "ChannelsDetailViewController.h"
#import "ChannelToolBarButton.h"
@interface ChanelDeTailToolBar ()
<
    UICollectionViewDelegate,
    UICollectionViewDataSource
>


@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@end


@implementation ChanelDeTailToolBar


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpAllChildrenView];
//        [self createView];
    }
    return self;
}

- (void)createView {
    ChannelToolBarButton *toolBarButton = [[ChannelToolBarButton alloc] initWithFrame:CGRectMake(0, 0, 100, 49)];
    toolBarButton.backgroundColor = [UIColor greenColor];
    [self addSubview:toolBarButton];
    _toolBarButton = toolBarButton;
    
}




- (void)setUpAllChildrenView {
    _layout = [[UICollectionViewFlowLayout alloc] init];
    _layout.itemSize = CGSizeMake(SCREEN_WIDTH / 2, 49);
    _layout.minimumLineSpacing = 0;
    _layout.minimumInteritemSpacing = 0;
    _toolBarCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 49) collectionViewLayout:_layout];
    [self addSubview:_toolBarCollectionView];
    _toolBarCollectionView.dataSource = self;
    _toolBarCollectionView.delegate = self;
    [_toolBarCollectionView registerNib:[UINib nibWithNibName:@"ChannelToolBarCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"ChannelToolBarCellReuse"];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    ChannelToolBarCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChannelToolBarCellReuse" forIndexPath:indexPath];
    if (indexPath.row == 0) {
        cell.contentView.backgroundColor = [UIColor blackColor];
        [cell.toolImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://qn.zheli.io/%@", _toolBar.star.img]]];
        cell.toolNameLabel.text = _toolBar.star.text;
    } else {
        cell.contentView.backgroundColor = [UIColor cyanColor];
        [cell.toolImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://qn.zheli.io/%@", _toolBar.join.img]]];
        cell.toolNameLabel.text = _toolBar.join.text;
    }
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"点击了");
    if (indexPath.item == 0) {
        NSLog(@"是否关注");
//        self.click();
        
    } else {
        NSLog(@"发帖");
        
    }
}


- (void)setToolBar:(ChannelPostToolbar *)toolBar {
    _toolBar = toolBar;
    [_toolBarCollectionView reloadData];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
